<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:general="http://java.sun.com/jsf/composite/components/general">
      
    <ui:composition template="template.xhtml">
        <ui:define name="dialogs">

             <general:confirmDialog
                widgetDialog="confirmRemoveDialog"
                dialogTitle="Remoção de centro de custo"
                message="Deseja remover o centro de custo selecionado?"
                buttonYesAction="#{centroCustoBean.remove()}"
                onclick_no_javascript="confirmRemoveDialog.hide()"
                onclick_yes_javascript="confirmRemoveDialog.hide()"
                onclick_yes_update=":growl :centroCustoform"/>

            <p:dialog header="Cadastro de centro de custo" widgetVar="newCentroCusto" modal="true" resizable="false">
                <p:panel id="panelCentroCusto" header="Centro custo" style="width: 310px">
                  
                    <h:form id="newCentroCustoform">
                          <h:panelGrid columns="2">
                            <h:outputText value="Nome: "  />
                            <p:inputText value="#{centroCustoBean.etapa.name}"  style="width: 170px"/>
                            <h:outputText value="Descrição: "  />
                            <p:inputText value="#{centroCustoBean.etapa.description}" style="width: 170px" />
                            
                          </h:panelGrid>
                        <p:separator />
                        <p:commandButton value="Salvar" action="#{centroCustoBean.save()}" update=":centroCustoform :growl" onclick="newCentroCusto.hide()" />
                    </h:form>
                  
                </p:panel>
            </p:dialog>

        </ui:define>
      


        <ui:define name="content">
            <h:form id="centroCustoform">
              <h:panelGrid columns="2">
                        <h:outputText value="Nome do centro de custo:" styleClass="formLabel" style="width: 120px"/>
                        <p:inputText id="centroCustoName" style="width: 300px" value="#{centroCustoBean.centroCustoFilter}"
                                     onclick="jQuery(this).select()">
                            <p:ajax event="keyup" update="centroCustoList" />
                        </p:inputText>

                        <p:watermark for="centroCustoName" value="Digite o nome do fornecedor" />
                    </h:panelGrid>
              <h:panelGroup id="centroCustoList">
                  <p:dataTable var="etapa" value="#{centroCustoBean.etapaList}"
                               paginator="true" rows="10" rowKey="#{etapa.id}"
                                     emptyMessage="Nenhum centro de custo foi encontrado"
                                     selectionMode="single" selection="#{centroCustoBean.etapaSelected}">

                            <p:ajax event="rowSelect" update="@this"/>

                            <f:facet name="header">
                                Lista de centro de custo
                            </f:facet>

                            <p:column style="width: 70%">
                                <f:facet name="header">
                                    <h:outputText value="Nome" />
                                </f:facet>
                                <h:outputText value="#{etapa.name}" />
                            </p:column>

                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="Descrição" />
                                </f:facet>
                                <h:outputText value="#{etapa.description}" />
                            </p:column>


                            <f:facet name="footer">
                                <p:commandButton icon="ui-icon ui-icon-plus" title="Adicionar centro de custo" update=":newCentroCustoform" oncomplete="newCentroCusto.show()"
                                                 disabled="#{not sharedPermissionManagedBean.hasPermission('CRIAR_CENTRO_CUSTO')}"/>
                                <p:commandButton icon="ui-icon ui-icon-pencil" title="Editar centro de custo"
                                                 disabled="#{(not sharedPermissionManagedBean.hasPermission('EDITAR_CENTRO_CUSTO')) or (centroCustoBean.etapaSelected.id == null)}"/>

                                <p:commandButton icon="ui-icon ui-icon-minus" title="Remover centro de custo" onclick="confirmRemoveDialog.show()"
                                                 disabled="#{(not sharedPermissionManagedBean.hasPermission('REMOVER_CENTRO_CUSTO')) or (centroCustoBean.etapaSelected.id == null)}"/>

                            </f:facet>
                        </p:dataTable>
                    </h:panelGroup>
            </h:form>
        </ui:define>
    </ui:composition>
</html>



